package com.zhongli.devplatform;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhongli.devplatform.component.FollowUtil;
import com.zhongli.devplatform.constant.Consts;
import com.zhongli.devplatform.po.user.ReadUserAttFansPO;
import com.zhongli.devplatform.po.user.ReadUserPO;
import com.zhongli.devplatform.service.imp.common.ReadUserAttFansService;
import com.zhongli.devplatform.service.imp.user.ReadUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wy
 * @date 2020/9/3
 */
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Autowired
    private ReadUserAttFansService userAttFansService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ZSetOperations<String, String> opsForZSet = redisTemplate.opsForZSet();
        List<ReadUserAttFansPO> list = userAttFansService.list();
        for (ReadUserAttFansPO item : list) {
            String attKey = Consts.USER_ATT + item.getFromUserId();//关注的人
            String fansKey = Consts.USER_FANS + item.getToUserId();//粉丝
            opsForZSet.add(attKey,item.getToUserId().toString(), 0); //我关注的人
            opsForZSet.add(fansKey, item.getFromUserId().toString(), 0); //我的粉丝
        }
    }
}
